import React, { Component } from 'react'
import './css/01-index.css'

export default class App extends Component {
  a = 100

  myref = React.createRef();

  state = {
    list : ["aa", "bb", "cc"]
  }

  render() {
    return (
      <div>
        <input ref= {this.myref}/>
        <button onClick ={ this.handleClick2}>add1</button>
        <ul>
          {
            this.state.list.map((item, index) => 
              <li key={item}>
                {/* {item} */}
                {/* 富文本展示 */}
                <span dangerouslySetInnerHTML={
                  {
                    __html:item
                  }
                }></span>
                <button onClick={() => this.handleDelClick(index)}>del</button>
              </li>
            )
          }
        </ul>
        {/* {this.state.list.length===0 ? <div>暂无代办事项</div> : nu  ll } */}
        {/* {this.state.list.length===0 && <div>暂无代办事项</div> }  */}
        <div className={this.state.list.length===0 ? '' : 'hidden'}>暂无代办事项</div>
      </div>
    )
  }

  handleClick2 = () => {
    console.log("click2", this.myref.current.value);
    let newlist = [...this.state.list];
    newlist.push(this.myref.current.value);
    this.setState({
      list: newlist
    })
    this.myref.current.value = "";
  }

  handleDelClick = (arg) => {
    console.log("del click", arg);
    let newlist = this.state.list.slice();
    // 和上面一条语句一样的效果
    // this.state.list.concat()
    newlist.splice(arg, 1);

    this.setState({
      list: newlist
    })
  }

}
